'''
人类, 汽车类, 一辆车名叫benz, 人名叫ming,如果人年龄小于18岁或者没有驾照不能驾驶汽车
汽车油箱50L, 每行驶100km, 会消耗10l油, 当油量低于10L, 会提示'请加油', 油量为0时不能行驶
汽车有里程表, 里程每5000km提示'请保养'
2021-8-15
'''


class CarMen:
    def __init__(self, name, age, jiazhao):
        self.name = name
        self.age = age
        self.jiazhao = jiazhao

    def drive(self, n, car):
        if self.age > 18 and self.jiazhao:
            car.go(n)
            return True
        return False

    def oil_add(self, n, car):
        if car.oil + n < 50:
            car.oil += n
        else:
            car.oil=50

    def __repr__(self):
        return f'name:{self.name},age:{self.age},jiazhao:{self.jiazhao}'


class Car:
    def __init__(self, name, oil):
        self.name = name
        if oil <= 50:
            self.oil = oil
        else:
            self.oil = 50
        self.move = 0

    def go(self, n):
        for i in range(n):
            if self.oil > 1:  # 有油
                self.move += 1
                self.oil -= 0.1
                if self.oil <= 10 and self.move%10==0:
                    print(f'请加油!目前油量:{self.oil}!')
                if self.move % 5000 == 0:
                    print('请保养!!')
            else:
                print('没油了,没法走了')
                break

    def __repr__(self):
        return f'name:{self.name},oil:{self.oil},move:{self.move}'


if __name__ == '__main__':
    mycar = Car('benz', 50)
    man = CarMen('ming', 19, True)
    man.drive(499, mycar)
    man.oil_add(50, mycar)
    man.drive(499, mycar)
    man.oil_add(50, mycar)
    man.drive(499, mycar)


    print(mycar)
